package com.recruit.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.recruit.dao.gen.mapper.ComResumeMapper;
import com.recruit.dao.gen.mapper.ResumeFileMapper;
import com.recruit.dao.gen.model.ComResume;
import com.recruit.dao.gen.model.ComResumeCriteria;
import com.recruit.dao.gen.model.Job;
import com.recruit.dao.gen.model.ResumeFile;
import com.recruit.dao.gen.model.ResumeFileExample;
import com.recruit.dao.gen.model.ResumeFileExample.Criteria;
import com.recruit.dto.ComResumeDto;
import com.recruit.service.ResumeService;
import com.recruit.util.JqueryDto;
import com.recruit.util.Pager;
@Service
public class ResumeServiceImpl implements ResumeService{
	@Resource
	ComResumeMapper resumeMapper;
	
	@Autowired
	ResumeFileMapper resumeFileMapper;
	
	@Override
	public boolean saveResume(ComResume user) {
		int i=resumeMapper.insert(user);
		if (i > 0) {
			return true;
		}

		return false;
	}

	@Override
	public JqueryDto queryResume(Pager pager, ResumeFile resumeFile, int userId) {
		ResumeFileExample resumeFileExample = new ResumeFileExample();
		resumeFileExample.setOrderByClause("order by create_time");
		Criteria criteria = resumeFileExample.createCriteria();
		criteria.andUserIdEqualTo(userId);
		// TODO Auto-generated method stub
		int total = resumeFileMapper.countByExample(resumeFileExample);
		int start = Integer.parseInt(pager.getPage()) - 1;

		List<ResumeFile> list = resumeFileMapper.queryResumeByUser(userId, start, Integer.parseInt(pager.getRows()));
		
		JqueryDto dto = new JqueryDto();
		dto.setTotal(total);
		pager.setObj(list);
		dto.setRows(list);
		return dto;
	}
	@SuppressWarnings("unchecked")
	@Override
	public ResumeFile getResumeInfoByFileId(String fileId) {
		
		ResumeFile resumeFile = resumeFileMapper.selectByPrimaryKey(Integer.parseInt(fileId));
		
		return resumeFile;
	}
	
	@Override
	public int saveResumeFile(ResumeFile resumeFile) {
		// TODO Auto-generated method stub
		return resumeFileMapper.insert(resumeFile);
	}
	
	
	@Override
	public int delFile(String fileId) {
		// TODO Auto-generated method stub
		return resumeFileMapper.deleteByPrimaryKey(Integer.parseInt(fileId));
	}
	
	
	@Override
	public JqueryDto queryFindApplyJob(Pager pager, int userId) {
		
		int total = resumeMapper.countFindApplyJob(userId);
		
		int start = Integer.parseInt(pager.getPage()) - 1;

		List<ComResumeDto> list = resumeMapper.queryFindApplyJob(userId, start, Integer.parseInt(pager.getRows()));
		
		JqueryDto dto = new JqueryDto();
		dto.setTotal(total);
		pager.setObj(list);
		dto.setRows(list);
		return dto;
	}
	
	
	@Override
	public JqueryDto findApplicationJobList(Pager pager, Integer comId) {
		// TODO Auto-generated method stub

		int total = resumeMapper.countFindApplicationJob(comId);
		
		int start = Integer.parseInt(pager.getPage()) - 1;

		List<ComResumeDto> list = resumeMapper.queryFindAppLicationJob(comId, start, Integer.parseInt(pager.getRows()));
		
		JqueryDto dto = new JqueryDto();
		dto.setTotal(total);
		pager.setObj(list);
		dto.setRows(list);
		return dto;
	}

	
	@Override
	public int update(ComResume comResume) {
		// TODO Auto-generated method stub
		return resumeMapper.updateByPrimaryKeySelective(comResume);
	}
}
